package com.itheima.mysocketdemo3;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建发送端Socket对象
        DatagramSocket ds = new DatagramSocket();
        //封装数据报包    -- 报文
        /*
         *   参数一: 字节数组,要发送的内容
         *   参数二: 字节数组的有效字节数
         *   参数三: 接收端地址
         *   参数四: 端口号
         * */
        String msg;
        Scanner sc = new Scanner(System.in);
        do {
            msg = sc.nextLine();
            //while (true) {
            DatagramPacket dp = new DatagramPacket(msg.getBytes(),
                    msg.getBytes().length,
                    InetAddress.getByName("192.168.13.44"),
                    10000);
            //基于Socket将数据发送出去
            ds.send(dp);
            //}
        } while (!"886".equals(msg));


        //关闭资源
        ds.close();
    }
}
